package com.jinlejia.bbs.adapter;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.graphics.Color;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.URLUtil;

import com.jinlejia.bbs.R;
import com.jinlejia.bbs.bean.GambitBean;
import com.jinlejia.bbs.bean.GambitListBean;
import com.jinlejia.bbs.bean.base.BBSUserBean;
import com.jinlejia.bbs.bean.base.BannerBean;
import com.jinlejia.bbs.bean.base.InformationBean;
import com.jinlejia.bbs.bean.base.SoundBean;
import com.jinlejia.bbs.bean.base.TopicBean;
import com.jinlejia.bbs.databinding.BbsAdapterBannerItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterHotItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterMessageItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterRecommendBinding;
import com.jinlejia.bbs.databinding.BbsAdapterSoundItemBinding;
import com.jinlejia.bbs.databinding.BbsAdapterTopicItemBinding;
import com.jinlejia.bbs.databinding.BbsMp3ViewLayoutBinding;
import com.jinlejia.bbs.logic.LikeFunLogic;
import com.jinlejia.bbs.ui.mine.others.BBSOtherUserMainActivity;
import com.jinlejia.bbs.ui.reply.BBSReplyDetailActivity;
import com.jinlejia.bbs.widget.BBSFlashView;
import com.jinlejia.bbs.widget.mp3.AudioController;
import com.jinlejia.bbs.widget.mp3.Mp3AdapterHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * 话题列表
 *
 * @author 王进 on 2019/3/5.
 */

public class GambitAdapter extends Mp3AdapterHelper<GambitListBean> {
    private static final int TYPE_MESSAGE = 1;
    private static final int TYPE_SOUND = 2;
    private static final int TYPE_FOOT = 4;
    private static final int TYPE_BANNER = 5;
    private static final int TYPE_RECOMMEND = 6;
    private static final int TYPE_HOT = 7;
    private static final int TYPE_TOPIC = 8;
    private HotListener hotListener;
    private RecommendAdapter adapter;
    private RecyclerView.LayoutManager layout;
    private GambitOnClickListener gambitOnClickListener;
    private LikeOnClickListener likeOnClickListener;

    private UserClickListener userClickListener;

    public GambitAdapter(Context context, AudioController audioController, RecyclerView recyclerView) {
        super(context, audioController, recyclerView);
        likeFunLogic = new LikeFunLogic(context);
    }

    private boolean isHot = false;
    public GambitAdapter(Context context, AudioController audioController, RecyclerView recyclerView,boolean isHot) {
        super(context, audioController, recyclerView);
        likeFunLogic = new LikeFunLogic(context);
        this.isHot = isHot;
    }

    @Override
    protected SoundBean getMp3SoundBean(int position) {
        ArrayList<GambitBean> list = mData.getGambitBeans();
        int index = getGambitSourceIndex(position);
        if (mData.getRecommendList()!=null && mData.getRecommendList().size()>0){
            if (index > 2) {
                index = index - 1;
            }
        }
        if (list!=null && list.size()>index){
            if (index>=0){
                GambitBean bean = list.get(index);
                return bean.getInfo().getSoundContent();
            }
        }
        return null;
    }

    @Override
    protected BbsMp3ViewLayoutBinding getMp3Binding(int position) {
        RecyclerView.ViewHolder holder = recyclerView.findViewHolderForLayoutPosition(position);
        BbsMp3ViewLayoutBinding mp3Binding = null;
        if (holder instanceof SoundViewHolder){
            BbsAdapterSoundItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
            mp3Binding = binding.musicView.getBinding();
        }
        return mp3Binding;
    }

    public interface UserClickListener{
        void onUserInfo(BBSUserBean user);
    }

    public void setUserClickListener(UserClickListener userClickListener) {
        this.userClickListener = userClickListener;
    }

    private LikeFunLogic likeFunLogic;


    public void setHotListener(HotListener hotListener) {
        this.hotListener = hotListener;
    }

    public void setLikeOnClickListener(LikeOnClickListener likeOnClickListener) {
        this.likeOnClickListener = likeOnClickListener;
    }

    @Override
    protected RecyclerView.ViewHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder;
        switch (viewType) {
            case TYPE_BANNER:
                viewHolder = new BannerViewHolder(inflater.inflate(R.layout.bbs_adapter_banner_item, parent, false));
                break;
            case TYPE_MESSAGE:
                viewHolder = new MessageViewHolder(inflater.inflate(R.layout.bbs_adapter_message_item, parent, false));
                break;
            case TYPE_FOOT:
                viewHolder = new FooterViewHolder(inflater.inflate(R.layout.bbs_adapter_footer_item, parent, false));
                break;
            case TYPE_RECOMMEND:
                viewHolder = new RecommendViewHolder(inflater.inflate(R.layout.bbs_adapter_recommend, parent, false));
                break;
            case TYPE_HOT:
                viewHolder = new HotViewHolder(inflater.inflate(R.layout.bbs_adapter_hot_item, parent, false));
                break;
            case TYPE_SOUND:
                viewHolder = new SoundViewHolder(inflater.inflate(R.layout.bbs_adapter_sound_item, parent, false));
                break;
            case TYPE_TOPIC:
                viewHolder = new TopicViewHolder(inflater.inflate(R.layout.bbs_adapter_topic_item, parent, false));
                break;
            default:
                throw new IllegalArgumentException("未知类型(" + viewType + ")");
        }
        return viewHolder;
    }
    //endregion

    @Override
    public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof BannerViewHolder) {
            bindBannerViewHolder((BannerViewHolder) holder, position);
        } else if (holder instanceof MessageViewHolder) {
            bindMessageViewHolder((MessageViewHolder) holder, position);
        } else if (holder instanceof FooterViewHolder) {
            bindFooterViewHolder((FooterViewHolder) holder, position);
        } else if (holder instanceof RecommendViewHolder) {
            bindRecommendViewHolder((RecommendViewHolder) holder, position);
        } else if (holder instanceof HotViewHolder) {
            bindHotViewHolder((HotViewHolder) holder, position);
        } else if (holder instanceof SoundViewHolder){
            bindSoundViewHolder((SoundViewHolder) holder,position);
        } else if (holder instanceof TopicViewHolder){
            bindTopicViewHolder((TopicViewHolder) holder,position);
        }
    }

    private void bindHotViewHolder(final HotViewHolder holder, int position) {
        BbsAdapterHotItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        binding.hotView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (hotListener != null) {
                    hotListener.onHot();
                }
            }
        });
    }

    private void bindRecommendViewHolder(RecommendViewHolder holder, int position) {
        BbsAdapterRecommendBinding binding = DataBindingUtil.getBinding(holder.itemView);
        ArrayList<BBSUserBean> list = mData.getRecommendList();
        if (adapter == null) {
            adapter = new RecommendAdapter(mContext,new RecommendAdapter.RecommendListener() {
                @Override
                public void onRecommend(final BBSUserBean userBean) {
                    Intent intent = new Intent();
                    intent.setClass(mContext,BBSOtherUserMainActivity.class);
                    intent.putExtra("pin",userBean.getUserPin());
                    mContext.startActivity(intent);
                }
            });
            layout = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
            binding.recyclerView.setLayoutManager(layout);
            binding.recyclerView.setAdapter(adapter);
        }
        adapter.setList(list);
        adapter.notifyDataSetChanged();
    }

    private void bindFooterViewHolder(FooterViewHolder holder, int position) {

    }

    public void setGambitOnClickListener(GambitOnClickListener gambitOnClickListener) {
        this.gambitOnClickListener = gambitOnClickListener;
    }


    @Override
    protected synchronized int getItemViewTypeZ(int position) {
        synchronized (mData){
            ArrayList<BannerBean> bannerList = mData.getBannerList();
            ArrayList<GambitBean> gambitList = mData.getGambitBeans();
            ArrayList<BBSUserBean> recommendList = mData.getRecommendList();

//            if ((bannerList == null || bannerList.size() == 0) && (gambitList == null || gambitList.size() == 0)) { //当没有数据时，展示空页面
//                return TYPE_EMPTY;
//            }

            if (position == 0) { //1. 尝试展示Banner
                if (bannerList != null && bannerList.size() > 0) { //2.1 如果bannerList有效，则展示Banner列表
                    return TYPE_BANNER;
                } else if (mData.isHotEnable()) {
                    return TYPE_HOT;
                } else if (gambitList!=null && gambitList.size()<2 && recommendList != null && recommendList.size()>0){
                    return TYPE_RECOMMEND;
                } else if (gambitList==null || gambitList.size()==0){
                    return TYPE_EMPTY;
                }
            }
            if (position == 1) { //2. 尝试展示热门话题
                if (bannerList != null && bannerList.size() > 0) { //当有Banner时，进行判断是否展示热门列表
                    if (mData.isHotEnable()) {
                        return TYPE_HOT;
                    }
                }
            }
            if (position == 2){
                if (gambitList == null || gambitList.size() == 0) {
                    return TYPE_EMPTY;
                }
            }

            int index = getGambitSourceIndex(position);
            if (gambitList!=null && gambitList.size()>=2 && index >= 2) {
                if (recommendList != null && recommendList.size() > 0) { //如果推荐列表有效
                    if (index == 2) {
                        return TYPE_RECOMMEND;
                    } else {
                        index = index - 1;
                    }
                }
            }else {
                if (gambitList!=null && gambitList.size()==index){
                    if (recommendList != null && recommendList.size() > 0){
                        return TYPE_RECOMMEND;
                    }
                }
            }
            int itemCount = getItemCount();
            if (position == itemCount - 1) {
                return TYPE_FOOT;
            } else {
                GambitBean bean = gambitList.get(index);
                InformationBean info = bean.getInfo();
                if (info==null){
                    return TYPE_TOPIC;
                }else
                if (info.getMessageContent() != null) {
                    return TYPE_MESSAGE;
                } else if (info.getSoundContent() != null) {
                    return TYPE_SOUND;
                } else {
                    return TYPE_TOPIC;
                }
            }
        }

    }

    //endregion

    private synchronized int getGambitSourceIndex(int position) {
        int index = position;
        ArrayList<BannerBean> bannerList = mData.getBannerList();
        if (bannerList != null && bannerList.size() > 0) {
            index = index - 1; //减去Banner行
        }
        if (mData.isHotEnable()) {
            index = index - 1;
        }
        return index;
    }

    @Override
    public synchronized int getItemCount() {
        if (mData==null){
            return 1;
        }
        ArrayList<BannerBean> bannerList = mData.getBannerList();
        ArrayList<GambitBean> gambitList = mData.getGambitBeans();
        ArrayList<BBSUserBean> recommendList = mData.getRecommendList();
        if ((bannerList == null || bannerList.size() == 0) && (gambitList == null || gambitList.size() == 0)){
            return 1;
        }
        int count = 0;
        if (bannerList != null) { //Banner
            count = count + 1;
        }
        if (gambitList != null) { //数据列表
            count = count + gambitList.size();
        }

        boolean hotEnable = mData.isHotEnable();
        if (hotEnable) { //热门
            count = count + 1;
        }

        if (recommendList != null && recommendList.size() > 0) { //推荐列表
            count = count + 1;
        }
        count = count + 1; //Footer
        return count;
    }

    public interface GambitOnClickListener {
        void onClickTopic(TopicBean bean);
    }

    public interface LikeOnClickListener{
        void onClickLike(TopicBean topic, InformationBean informationBean, int position);
    }

    public interface HotListener {
        void onHot();
    }

    //region 热门话题行
    class HotViewHolder extends RecyclerView.ViewHolder {

        HotViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    //region 推荐行
    class RecommendViewHolder extends RecyclerView.ViewHolder {

        RecommendViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }
    //endregion

    //region Footer
    class FooterViewHolder extends RecyclerView.ViewHolder {

        FooterViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    //region 文本消息行
    class MessageViewHolder extends RecyclerView.ViewHolder {

        MessageViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindMessageViewHolder(MessageViewHolder holder, final int position) {
        BbsAdapterMessageItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        ArrayList<GambitBean> list = mData.getGambitBeans();
        int index = getGambitSourceIndex(position);
        if (mData.getRecommendList()!=null && mData.getRecommendList().size()>0){
            if (index > 2) {
                index = index - 1;
            }
        }

        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        final InformationBean information = bean.getInfo();
        List<BBSUserBean> likeList = information.getLikeUserList();
        if (likeList!=null && likeList.size()>0){
            for (int i = 0; i < likeList.size(); i++) {
                switch (i){
                    case 0:
                        binding.setUser1(likeList.get(i));
                        break;
                    case 1:
                        binding.setUser2(likeList.get(i));
                        break;
                    case 2:
                        binding.setUser3(likeList.get(i));
                        break;
                    case 3:
                        binding.setUser4(likeList.get(i));
                        break;
                    default:
                        break;
                }
            }
        }else {
            binding.setUser1(null);
            binding.setUser2(null);
            binding.setUser3(null);
            binding.setUser4(null);
        }
        if (information.isOwnLike()) {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }
        if (isHot){
            binding.readCountTextView.setVisibility(View.GONE);
            binding.hotReadCountTextView.setVisibility(View.VISIBLE);
        }else {
            binding.readCountTextView.setVisibility(View.VISIBLE);
            binding.hotReadCountTextView.setVisibility(View.GONE);
        }
        View.OnClickListener topicListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gambitOnClickListener != null) {
                    gambitOnClickListener.onClickTopic(bean.getTopic());
                }else {
                    Intent intent = new Intent();
                    intent.putExtra("topic",bean.getTopic());
                    intent.setClass(mContext, BBSReplyDetailActivity.class);
                    mContext.startActivity(intent);
                }
            }
        };
        binding.topicClickView.setOnClickListener(topicListener);
        binding.userAnswerTextView.setOnClickListener(topicListener);
        binding.titleTextView.setOnClickListener(topicListener);
        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InformationBean info = bean.getInfo();
                if (likeOnClickListener!=null){
                    TopicBean topic = bean.getTopic();
                    likeOnClickListener.onClickLike(topic,info,position);
                }else {
                    likeFunLogic.execute(info.getAnswerCode(), new LikeFunLogic.LogicCallBack() {
                        @Override
                        public void onResult(boolean likeState) {
                            information.setOwnLike(likeState);
                            if (likeState){
                                information.setLikeCount(information.getLikeCount()+1);
                            }else {
                                information.setLikeCount(information.getLikeCount()-1);
                            }
                            notifyItemChanged(position);
                        }
                    });
                }
            }
        });
        View.OnClickListener toUserListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BBSUserBean user = bean.getInfo().getUser();
                if (userClickListener!=null){
                    userClickListener.onUserInfo(user);
                }else {
                    Intent intent = new Intent();
                    intent.setClass(mContext, BBSOtherUserMainActivity.class);
                    String pin = user.getUserPin();
                    intent.putExtra("pin",pin);
                    mContext.startActivity(intent);
                }
            }
        };
        //点击头像跳转
        binding.userAvatarImageView.setOnClickListener(toUserListener);
        binding.userAnswerTextView.setText(bean.getInfo().getMessageContent());

    }
    //endregion

    //region 声音行
    class SoundViewHolder extends RecyclerView.ViewHolder {
        SoundViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindSoundViewHolder(SoundViewHolder holder, final int position) {
        final BbsAdapterSoundItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        ArrayList<GambitBean> list = mData.getGambitBeans();
        int index = getGambitSourceIndex(position);
        if (mData.getRecommendList()!=null && mData.getRecommendList().size()>0){
            if (index > 2) {
                index = index - 1;
            }
        }
        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        List<BBSUserBean> likeList = bean.getInfo().getLikeUserList();
        if (likeList!=null && likeList.size()>0){
            for (int i = 0; i < likeList.size(); i++) {
                switch (i){
                    case 0:
                        binding.setUser1(likeList.get(i));
                        break;
                    case 1:
                        binding.setUser2(likeList.get(i));
                        break;
                    case 2:
                        binding.setUser3(likeList.get(i));
                        break;
                    case 3:
                        binding.setUser4(likeList.get(i));
                        break;
                    default:
                        break;
                }
            }
        }else {
            binding.setUser1(null);
            binding.setUser2(null);
            binding.setUser3(null);
            binding.setUser4(null);
        }
        if (isHot){
            binding.readCountTextView.setVisibility(View.GONE);
            binding.hotReadCountTextView.setVisibility(View.VISIBLE);
        }else {
            binding.readCountTextView.setVisibility(View.VISIBLE);
            binding.hotReadCountTextView.setVisibility(View.GONE);
        }
        InformationBean info = bean.getInfo();

        final SoundBean content = info.getSoundContent();
        initMp3View(binding.musicView.getBinding(),content,position);
        final InformationBean information = bean.getInfo();
        if (information.isOwnLike()) {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#FCD01A"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_select);
        } else {
            binding.userLikeCountTextView.setTextColor(Color.parseColor("#999999"));
            binding.userLikeIconImageView.setImageResource(R.mipmap.bbs_like_icon_normal);
        }
        View.OnClickListener toTopicListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gambitOnClickListener != null) {
                    gambitOnClickListener.onClickTopic(bean.getTopic());
                }else {
                    Intent intent = new Intent();
                    intent.putExtra("topic",bean.getTopic());
                    intent.setClass(mContext, BBSReplyDetailActivity.class);
                    mContext.startActivity(intent);
                }
            }
        };
        binding.topicClickView.setOnClickListener(toTopicListener);
        binding.userAnswerTextView.setOnClickListener(toTopicListener);
        binding.titleTextView.setOnClickListener(toTopicListener);
        binding.titleTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gambitOnClickListener != null) {
                    gambitOnClickListener.onClickTopic(bean.getTopic());
                }else {
                    Intent intent = new Intent();
                    intent.putExtra("topic",bean.getTopic());
                    intent.setClass(mContext, BBSReplyDetailActivity.class);
                    mContext.startActivity(intent);
                }
            }
        });
        binding.userAnswerTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gambitOnClickListener != null) {
                    gambitOnClickListener.onClickTopic(bean.getTopic());
                }
            }
        });
        binding.likeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (likeOnClickListener!=null){
                    InformationBean info = bean.getInfo();
                    TopicBean topic = bean.getTopic();
                    likeOnClickListener.onClickLike(topic,info,position);
                }else {
                    InformationBean info = bean.getInfo();
                    likeFunLogic.execute(info.getAnswerCode(), new LikeFunLogic.LogicCallBack() {
                        @Override
                        public void onResult(boolean likeState) {
                            information.setOwnLike(likeState);
                            if (likeState){
                                information.setLikeCount(information.getLikeCount()+1);
                            }else {
                                information.setLikeCount(information.getLikeCount()-1);
                            }
                            notifyItemChanged(position);
                        }
                    });
                }
            }
        });
        View.OnClickListener toUserListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BBSUserBean user = bean.getInfo().getUser();
                if (userClickListener!=null){
                    userClickListener.onUserInfo(user);
                }else {
                    Intent intent = new Intent();
                    intent.setClass(mContext, BBSOtherUserMainActivity.class);
                    String pin = user.getUserPin();
                    intent.putExtra("pin",pin);
                    mContext.startActivity(intent);
                }
            }
        };
//        binding.userNameTextView.setOnClickListener(toUserListener);
//        binding.userAddressTextView.setOnClickListener(toUserListener);
        binding.userAvatarImageView.setOnClickListener(toUserListener);
    }
    //endregion

    //region Banner数据行
    class BannerViewHolder extends RecyclerView.ViewHolder {

        BannerViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindBannerViewHolder(BannerViewHolder holder, int position) {
        BbsAdapterBannerItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        List<String> urls = new ArrayList<>();
        final ArrayList<BannerBean> bannerList = mData.getBannerList();
        for (BannerBean bean : bannerList) {
            urls.add(bean.getImageUrl());
        }
        binding.flashView.setImagesUrl(urls);
        binding.flashView.setOnItemClickListener(new BBSFlashView.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                BannerBean bean = bannerList.get(position);
                if (bean.getState()== BannerBean.State.TOPIC){ //跳转至话题详情
                    Intent intent = new Intent();
                    TopicBean topicBean = new TopicBean();
                    topicBean.setTopicCode(bean.getLink());
                    intent.setClass(mContext,BBSReplyDetailActivity.class);
                    intent.putExtra("topic",topicBean);
                    mContext.startActivity(intent);
                }else {
                    if (!URLUtil.isNetworkUrl(bean.getLink())){
                        return;
                    }
                    Class webClass = null;
                    try {
                        webClass= Class.forName("com.jinlejia.erp.ui.common.WebViewActivity");
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                    if (webClass!=null){
                        Intent intent = new Intent();
                        intent.setClass(mContext,webClass);
                        intent.putExtra("url",bean.getLink());
                        mContext.startActivity(intent);
                    }
                }
            }
        });
    }
    //endregion

    private static class TopicViewHolder extends RecyclerView.ViewHolder{

        TopicViewHolder(View itemView) {
            super(itemView);
            DataBindingUtil.bind(itemView);
        }
    }

    private void bindTopicViewHolder(TopicViewHolder holder,int position){
        BbsAdapterTopicItemBinding binding = DataBindingUtil.getBinding(holder.itemView);
        ArrayList<GambitBean> list = mData.getGambitBeans();
        int index = getGambitSourceIndex(position);
        if (mData.getRecommendList()!=null && mData.getRecommendList().size()>0){
            if (index > 2) {
                index = index - 1;
            }
        }
        final GambitBean bean = list.get(index);
        binding.setBean(bean);
        binding.rootLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (gambitOnClickListener != null) {
                    gambitOnClickListener.onClickTopic(bean.getTopic());
                }else {
                    Intent intent = new Intent();
                    intent.putExtra("topic",bean.getTopic());
                    intent.setClass(mContext, BBSReplyDetailActivity.class);
                    mContext.startActivity(intent);
                }
            }
        });
    }
}
